#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
//check_args
int	main(int argc, char **argv)
{
  char *pval = NULL;
  char *xval = NULL;
  char *yval = NULL;
  char *nval = NULL;
  char *cval = NULL;
  char *tval = NULL;
  int index;
  int c;
  
  opterr = 0;
  
  while ((c = getopt (argc, argv, "p:x:y:n:c:t:")) != -1)
    switch (c)
      {
      case 'p':
	//pval = optarg;
	checkport(atoi(optarg));
	break;
      case 'x':
	xval = optarg;
	break;
      case 'y':
	yval = optarg;
	break;
      case 'n':
	nval = optarg;
	printf ("%s-->", optarg++ );
	break;
      case 'c':
	cval = optarg;
	break;
      case 't':
	tval = optarg;
	break;

      case '?':
	if (optopt == 'p')
               fprintf (stderr, "Option -%p requires an argument.\n", optopt);
	else if (optopt == 'x')
               fprintf (stderr, "Option -%x requires an argument.\n", optopt);
	else if (optopt == 'y')
	  fprintf (stderr, "Option -%y requires an argument.\n", optopt);
	else if (optopt == 'n')
               fprintf (stderr, "Option -%n requires an argument.\n", optopt);
	else if (optopt == 'c')
               fprintf (stderr, "Option -%c requires an argument.\n", optopt);
	else if (optopt == 't')
               fprintf (stderr, "Option -%t requires an argument.\n", optopt);
	else if (isprint (optopt))
	  fprintf (stderr, "Unknown option `-%h'.\n", optopt);
	else
	  fprintf (stderr,
		   "Unknown option character `\\x%x'.\n",
		   optopt);
	return 1;
      default:
	abort ();
      }
  
  printf ("pval = %s, xval = %s, yval = %s, nval = %s, cval = %s, tval = %s\n",
	  pval, xval, yval, nval, cval, tval);
  for (index = optind; index < argc; index++)
    printf ("Non-option argument %s\n", argv[index]);
  return 0;
}
